<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>钥匙记录</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/js/global.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
        .selectlabe1{
        	width: 110px;
        }
        .div1{
        	padding-left:0px;
        	width: 210px;
        }
        .div2{
        	 padding-left: 0px;
   			 width: 196px;
		}
        .selectdivs{
        	 padding-left: 0px;
   			 width: 150px;
		}
        .butt{
        	width: 100px;
		}
		.left ul li{
			
			*line-height:40px;
			
			*padding-left:20px;
		}
		
		.left ul li a, .left ul li a:hover{
			*color:#fff;
		}
		.wrapper{
			*margin-left:270px;
		}
		.form-group{
			*overflow: hidden;
		}
		.btn{
			*width:60px;
		}
		.lt{
			float:left;
		}
		.form-control{
			*padding:0;
		}
		.ui-pg-button{
			*background:#ccc;
		}
		.selectlabe1{
			width:90px !important;
		}
		.col-md-1{*+padding-left:0;}
    </style>
</head>
<body view="menu-item-4142">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
 	<div class="wrapper">
        <div class="panel panel-default">
            <div class="panel-heading">
                <span><strong>查询条件</strong></span>

                <div class="ibox-tools">
                    <a class="collapse-link"> <i class="fa fa-chevron-down"></i></a>
                    <a class="collapse-link  d-n"> <i class="fa fa-chevron-up"></i></a>
                </div>
            </div>
            <div class="panel-body">
                <form class="form-horizontal">
                     <c:if test="${userRole == 1 || userRole == 2 || userRole == 21}">
	                    <div class="form-group">
	                        <label class="selectlabe1 col-md-1 lt form-lable">公司名称：</label>
	                        <div class="selectdivs col-md-3 lt" >
	                            <select name="agtCode" id="agtCode" class="form-control col-md-1 lt"></select>
	                        </div>
	                        
	                        <label class="selectlabe2 col-md-1 lt form-lable">小区名称：</label>
	                        <div class="selectdivs lt col-md-3">
	                            <select name="communityId" id="communityId" class="form-control col-md-1 lt"></select>
	                        </div>
	                      	<label class="selectlabe2 col-md-1 lt form-lable">所属区域：</label>
				            <div id="region" class="col-md-3 lt" style="width: 16%;padding-left: 0px;">
				                <script type="text/javascript">
				                    loadCity();
				                </script>
				            </div>
	                      </div>
			          </c:if>
			          <c:if test="${userRole == 3 || userRole == 4}">
				          <div class="form-group">
				          	<c:if test="${rLevel == 3 || rLevel == 4}">
								<label class="selectlabe1  lt col-md-1 form-lable" style="width: 110px;">主用户：</label>
		                 	</c:if>
		                 	<c:if test="${rLevel != 3 && rLevel != 4}">
								<label class="selectlabe1 lt col-md-1 form-lable" style="width: 110px;">小区名称：</label>
		                 	</c:if>
	                        <div class="selectdivs col-md-3 lt">
	                            <select name="communityId" id="communityId" class="form-control col-md-1 lt"></select>
	                        </div>
	                        	<label class="selectlabe2 col-md-1 lt form-lable">发放时间：</label>
                        	<div class="selectdivs col-sm-3 lt">
	                            <div class=" input-group lt">
	                                <input class="form-control" name="reqtime" id='reqtime'
	                                       onclick='WdatePicker()'/>
	                            </div>
                        	</div>
	                      	<label class="selectlabe2 lt col-md-1 form-lable">所属区域：</label>
				            <div id="region" class="col-md-3  lt" style="width: 16%;padding-left: 0px;">
				                <script type="text/javascript">
				                    loadCity();
				                </script>
				            </div>
				          </div>
				          <div class="form-group">
					          <label class="selectlabe1 col-md-1 lt form-lable">有效期：</label>
	                        	<div class="selectdivs col-sm-3 lt">
		                            <div class=" input-group lt">
		                                <input class="form-control" name="validity" id='validity'
		                                       onclick='WdatePicker()'/>
		                            </div>
	                          </div>
	                          <label class="selectlabe2 col-md-1 lt form-lable">PID：</label>
                        	<div class="selectdivs col-md-3 lt" >
                            	<input id="pid" name="pid" type="text" class="form-control"/>
                        	</div>
                        	<c:if test="${rLevel == 3 || rLevel == 4}">
                        	<label class="selectlabe2 col-md-1 form-lable lt" >智能锁名：</label>
                        	</c:if>
                        	<c:if test="${rLevel != 3 && rLevel != 4}">
                        	<label class="selectlabe2 col-md-1 form-lable lt" >门禁名称：</label>
                        	</c:if>
	                        <div class="selectdivs col-md-3 lt">
	                            <input id="cbName" name="cbName" type="text" class="form-control"/>
	                        </div>
                          </div>
				          <div class="form-group">
				          	
	                      	<label class="selectlabe1 col-md-1 form-lable lt">手机号：</label>
	                        <div class="selectdivs col-md-3 lt">
	                            <input id="tel" name="tel" type="text" class="form-control"/>
	                        </div>
		                    <label class="selectlabe2 col-md-1 form-lable lt">用户：</label>
	                        <div class="selectdivs col-md-3 lt" >
	                            <input id="userName" name="userName" type="text" class="form-control"/>
	                        </div>    
	                        <div class="col-md-1 form-action lt">
	                            <button class="btn btn-success form-control" id="query">查询</button>
	                        </div>
	                        <div class="col-md-1 form-action lt">
	                            <button class="btn btn-success form-control" id="resetForm">清空</button>
	                        </div>
				          </div>
			          </c:if>
                     <c:if test="${userRole == 1 || userRole == 2 || userRole == 21 || userRole == 5 || userRole == 6}">
                     <div class="form-group">
                        <c:if test="${rLevel == 3 || rLevel == 4}">
	                        <label class="selectlabe1 col-md-1 form-lable lt">申请时间：</label>
                       	</c:if>
                       	<c:if test="${rLevel != 3 && rLevel != 4}">
                       		<label class="selectlabe1 col-md-1 form-lable lt">发放时间：</label>
                       	</c:if>
                        <div class="selectdivs col-sm-3 lt">
                            <div class=" input-group lt">
                                <input class="form-control" name="reqtime" id='reqtime'
                                       onclick='WdatePicker()'/>
                            </div>
                        </div>
                      	<label class="selectlabe2 col-md-1 form-lable lt">有效期：</label>
                        <div class="selectdivs col-sm-3 lt">
                            <div class=" input-group lt">
                                <input class="form-control" name="validity" id='validity'
                                       onclick='WdatePicker()'/>
                            </div>
                        </div>
                      	<label class="selectlabe2 col-md-1 form-lable lt">PID：</label>
                        <div class="selectdivs col-md-3 lt" >
                            <input id="pid" name="pid" type="text" class="form-control"/>
                        </div>
                      </div>
                      <div class="form-group">
                      
                     	<c:if test="${rLevel == 3 || rLevel == 4}">
                       		<label class="selectlabe1 col-md-1 form-lable lt" >智能锁名：</label>
                       	</c:if>
                       	<c:if test="${rLevel != 3 && rLevel != 4}">
                       		<label class="selectlabe1 col-md-1 form-lable lt" >门禁名称：</label>
                       	</c:if>
                        <div class="selectdivs col-md-3 lt">
                            <input id="cbName" name="cbName" type="text" class="form-control"/>
                        </div>
                      	<label class="selectlabe2 col-md-1 form-lable lt">手机号：</label>
                        <div class="selectdivs col-md-3 lt">
                            <input id="tel" name="tel" type="text" class="form-control"/>
                        </div>
	                    <label class="selectlabe2 col-md-1 form-lable lt">用户：</label>
                        <div class="selectdivs col-md-3 lt" >
                            <input id="userName" name="userName" type="text" class="form-control"/>
                        </div>    
                        <div class="col-md-1 form-action lt">
                            <button class="btn btn-success form-control" id="query">查询</button>
                        </div>
                        <div class="col-md-1 form-action lt">
                            <button class="btn btn-success form-control" id="resetForm">清空</button>
                        </div>
                    </div>
                    </c:if>
                      
                     
                </form>
            </div>
        </div>
	    <div class="jqGrid_wrapper">
	        <div id="jqGrid_operation" class="jg-grid">
	            <h1>钥匙记录</h1>
	            <div class="jqGrid_operation" id="action"></div>
	        </div>
	        <table id="jqGrid"></table>
	        <div id="jqGrid_paper"></div>
	    </div>
	</div>
</div>
<script>
    $(document).ready(
            function () {
                $("#action").append("<a id=\"batchupdate\"><i class=\"glyphicon glyphicon-edit\"></i>批量修改有效期</a>");
                $("#batchupdate").click(function(){
                	var sids = $("#jqGrid").jqGrid('getGridParam','selarrrow');
                	var selectedId = $("#jqGrid").jqGrid('getGridParam','selrow');
                	var rowData  = $("#jqGrid").jqGrid("getRowData", selectedId);
                	var str1 = rowData.VALIDITY1.split('>');
                	var validity = str1[1].split('<')[0];
                	layer.open({
                        type: 2,
                        title: ['修改钥匙有效期', 'font-weight:bold'],
                        shadeClose: true, //点击遮罩关闭层
                        area: ['387px', '358px'],
                        scrollbar: false,
                        content: '${pageContext.request.contextPath}/admin/tkeys_changeKeysValidity.action?sid='+sids+'&validity='+validity,
                        btn: ['提交', '取消'],
                        yes: function (index, layero) {
                            var options = {
                                success: function (data) {
                                    data = JSON.parse(data);
                                    if (data.code == 1) {
                                        layer.alert(data.msg, function () {
                                            layer.closeAll();
                                            refreshGrid();
                                        });
                                    } else {
                                        layer.alert(data.msg);
                                    }
                                }
                            };
                            $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
                            $("#layui-layer-iframe" + index).contents().find("#form").submit();
                        },
                        cancel: function (index, layero) {
                            layer.close(index);
                        }
                    });	
                });
                $.jgrid.defaults.styleUI = "Bootstrap";
                if('${rLevel}'==3 || '${rLevel}'==4){//锁厂
	                $("#jqGrid").jqGrid({
	                      url: "${pageContext.request.contextPath}/admin/tkeys_page.action",
	                      mtype: 'POST',
	                      datatype: "json",
	                      height: 350,
	                      autowidth: true,
	                      shrinkToFit: true,
	                      rowNum: 10,
	                      rowList: [10, 20, 30],
	                      colNames: ['序号','所属区域', '公司名称', '主用户','智能锁名称', 'PID',  
	                          '姓名', '手机号 ', '状态', '发放时间','有效期','状态'],
	                      colModel: [{
	                          name: "SID",
	                          index: "SID",
	                          key: true,
	                          hidden: true
	                      }, {
	                          name: 'CITYCODE',
	                          index: 'CITYCODE'
	                      }, {
	                          name: 'AGTNAME',
	                          index: 'AGTNAME'
	                      }, {
	                          name: 'COMMUNITYNAME',
	                          index: 'COMMUNITYNAME'
	                      },{
	                          name: 'LOCK_NAME',
	                          index: 'LOCK_NAME'
	                      },{
	                          name: 'PID',
	                          index: 'PID'
	                      },{
	                          name: "AUNAME",
	                          index: "AUNAME"
	                      }, {
	                          name: "TEL",
	                          index: "TEL"
	                          
	                      },{
	                          name: "UTYPE",
	                          index: "UTYPE",
	                          formatter: "select",
	                          width: 50,
	                          editoptions: {value: "1:户主;2:主租客;3:住户;4:租客"}
	                          
	                      }, {
	                          name: "REQTIME",
	                          index: "REQTIME"
	                          
	                      },{
	                          name: "VALIDITY1",
	                          index: "VALIDITY1",
	                          formatter: function (cellvalue, options, rawObject) {
	                              if(cellvalue!= ""){
	                              	return '<a style="border-bottom:1px solid #337ab7;" onclick="overdueKeys('+rawObject.SID+',\''+cellvalue+'\')" >'+cellvalue+'</a>';
	                              }else{ 
	                                  return '';
	                              }
	                          }
	                      }, {
	                          name: "STATUS_",
	                          index: "STATUS_",
	                          formatter: function (cellvalue, options, rawObject) {
	                              if(cellvalue!= ""&&typeof(cellvalue)!="undefined"){
	                            	  if(cellvalue=='2'){
	                                  	return '换锁失效';
	                                  }
		  	                      
	  	                        	if (cellvalue == '-1000') {
	  	                        		return '<input type="button" style="padding: 2px 10px" class="btn btn-success" value="已过期 " onmouseover="this.value=\'延长日期\';" onmouseout="this.value=\'已过期\';" onclick="overdueKeys('
	  	                        		+rawObject.SID+',\''+rawObject.VALIDITY1+'\')"/>';
	  								}else{
	  									if(cellvalue == '0'){
	  		                                 return '<input type="button" style="padding: 2px 10px" class="btn btn-success" onmouseover="this.value=\'停用\';" onmouseout="this.value=\'正常\';" value="正常" onclick="changeKeys('
	  		                                 + rawObject.SID + ',1)"/>';
	  		                             }else{
	  		                            	 return '<input type="button" style="padding: 2px 10px" class="btn btn-success" value="已停用 " onmouseover="this.value=\'恢复正常\';" onmouseout="this.value=\'已停用\';" onclick="changeKeys('
	  		                                 + rawObject.SID + ',0)"/>';
	  		                             }
	  								}
	                              }else{
	                                  return '';
	                              }
	                         }
	                      }],
	                      sortname: 'req_time',
	                      sortorder:'desc',
	                      rownumbers: true,
	                      jsonReader: {
	                          root: 'rows',
	                          page: "page",
	                          total: 'total',
	                          records: "records",
	                          repeatitems: false
	                      },
	                      pager: "#jqGrid_paper",
	                      viewrecords: true,
	                      multiselect: true,
	                      hidegrid: false,
	                      loadComplete: function(){
	                  		var re_records = Number($("#jqGrid").getGridParam('records'));
	                  		var page = Number($("#jqGrid").getGridParam('page'));
	                  		var rows=Number($("#jqGrid").getGridParam('rowNum'));
	                  		var num = re_records-(page-1)*rows;
	                  		if(num < rows)
	                  		{
	                  			for(var i=num;i<rows;i++){
	                  				$("#jqGrid").jqGrid("addRowData",(i+1),
	                          				{ "SID":"", "CITYCODE":"", "AGTNAME":"", "COMMUNITYNAME":"", "PID":"", "LOCK_NAME":"", "VALIDITY1":"", "AUNAME":"", "TEL":"", "REQTIME":""}
	                  				,"");
	                  			}
	                  			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
	                  		}
	                  	}
	                  });
                }else{
	                $("#jqGrid").jqGrid({
	                      url: "${pageContext.request.contextPath}/admin/tkeys_page.action",
	                      mtype: 'POST',
	                      datatype: "json",
	                      height: 420,
	                      autowidth: true,
	                      shrinkToFit: true,
	                      rowNum: 10,
	                      rowList: [10, 20, 30],
	                      colNames: ['序号','所属区域', '公司名称', '小区名称','门禁名称', 'PID',  
	                          '姓名', '手机号 ', '状态', '发放时间','有效期','状态'],
	                      colModel: [{
	                          name: "SID",
	                          index: "SID",
	                          key: true,
	                          hidden: true
	                      }, {
	                          name: 'CITYCODE',
	                          index: 'CITYCODE'
	                      }, {
	                          name: 'AGTNAME',
							  width:80,
	                          index: 'AGTNAME'
	                      }, {
	                          name: 'COMMUNITYNAME',
							  width:80,
	                          index: 'COMMUNITYNAME'
	                      },{
	                          name: 'LOCK_NAME',
	                          index: 'LOCK_NAME'
	                      }, {
	                          name: 'PID',
	                          index: 'PID'
	                      }, {
	                          name: "AUNAME",
							   width:70,
	                          index: "AUNAME",
	                          width: 80
	                      }, {
	                          name: "TEL",
							   width:90,
	                          index: "TEL"
	                          
	                      }, {
	                          name: "UTYPE",
	                          index: "UTYPE",
	                          formatter: "select",
	                          width: 80,
	                          editoptions: {value: "1:户主;2:主租客;3:住户;4:租客"}
	                          
	                      },{
	                          name: "REQTIME",
	                          index: "REQTIME"
	                          
	                      }, {
	                          name: "VALIDITY1",
	                          index: "VALIDITY1",
	                          formatter: function (cellvalue, options, rawObject) {
	                              if(cellvalue!= ""){
	                              	return '<a style="border-bottom:1px solid #337ab7;" onclick="overdueKeys('+rawObject.SID+',\''+cellvalue+'\')" >'+cellvalue+'</a>';
	                              }else{ 
	                                  return '';
	                              }
	                          }
	                      }, {
	                          name: "STATUS_",
							   width:100,
	                          index: "STATUS_",
	                          formatter: function (cellvalue, options, rawObject) {
	                        	  if(cellvalue!= ""&&typeof(cellvalue)!="undefined"){
	                        		if (cellvalue == '-1000') {
	  	                        		return '<input type="button" style="padding: 2px 10px" class="btn btn-success" value="已过期 " onmouseover="this.value=\'延长日期\';" onmouseout="this.value=\'已过期\';" onclick="overdueKeys('
	  	                        		+rawObject.SID+',\''+rawObject.VALIDITY1+'\')"/>';
	  								}else{
	  									if(cellvalue == '0'){
	  		                                 return '<input type="button" style="padding: 2px 10px" class="btn btn-success" onmouseover="this.value=\'停用\';" onmouseout="this.value=\'正常\';" value="正常" onclick="changeKeys('
	  		                                 + rawObject.SID + ',1)"/>';
	  		                             }else{
	  		                            	 return '<input type="button" style="padding: 2px 10px" class="btn btn-success" value="已停用 " onmouseover="this.value=\'恢复正常\';" onmouseout="this.value=\'已停用\';" onclick="changeKeys('
	  		                                 + rawObject.SID + ',0)"/>';
	  		                             }
	  								}
	                              }else{
	                                  return '';
	                              }
	                         }
	                      }],
	                      sortname: 'req_time',
	                      sortorder:'desc',
	                      rownumbers: true,
	                      jsonReader: {
	                          root: 'rows',
	                          page: "page",
	                          total: 'total',
	                          records: "records",
	                          repeatitems: false
	                      },
	                      pager: "#jqGrid_paper",
	                      viewrecords: true,
	                      multiselect: true,
	                      hidegrid: false,
	                      loadComplete: function(){
	                  		var re_records = Number($("#jqGrid").getGridParam('records'));
	                  		var page = Number($("#jqGrid").getGridParam('page'));
	                  		var rows=Number($("#jqGrid").getGridParam('rowNum'));
	                  		var num = re_records-(page-1)*rows;
	                  		if(num < rows)
	                  		{
	                  			for(var i=num;i<rows;i++){
	                  				$("#jqGrid").jqGrid("addRowData",(i+1),
	                          				{ "SID":"", "CITYCODE":"", "AGTNAME":"", "COMMUNITYNAME":"", "PID":"", "LOCK_NAME":"", "VALIDITY1":"", "AUNAME":"", "TEL":"", "REQTIME":""}
	                  				,"");
	                  			}
	                  			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
	                  		}
	                  	}
	                  });
                }
                if('${userRole}' == '1' || '${userRole}' == '2' || '${userRole}' == '21'){
	                $.post("${pageContext.request.contextPath}/admin/tagent_list.action", function (data) {
			            $("#agtCode").empty();
			            $("#agtCode").append("<option value=''>请选择公司</option>");
			            for (var i = 0; i < data.length; i++) {
			                $("#agtCode").append("<option value='" + data[i].agtCode + "'>" + data[i].agtName + "</option>");
			            }
			            $("#agtCode").select2({
			                "placeholder": "请选择公司",
			                "width": "100%"
			            })
			            $("#agtCode").change(function () {
			            	var data = $(this).val();
			            	$.post("${pageContext.request.contextPath}/admin/tcommunity_list.action", {"agtCode": data},function (data) {
					            $("#communityId").empty();
					            $("#communityId").append("<option value=''>请选择社区</option>");
					            for (var i = 0; i < data.length; i++) {
					                $("#communityId").append("<option value='" + data[i].sid + "'>" + data[i].communityName + "</option>");
					            }
					            $("#communityId").select2({
					                "placeholder": "请选择社区",
					                "width": "100%"
					            })
					        }, "json");
			            })
			        }, "json");
                }else if('${userRole}' == '3' || '${userRole}' == '4' ){
                	$.post("${pageContext.request.contextPath}/admin/tcommunity_list.action", 
                        function (data) {
			            $("#communityId").empty();
			            if('${rLevel}'==3 || '${rLevel}'==4){
			            	$("#communityId").append("<option value=''>请选择</option>");
				        }else{
			            	$("#communityId").append("<option value=''>请选择社区</option>");
					    }
			            for (var i = 0; i < data.length; i++) {
			                $("#communityId").append("<option value='" + data[i].sid + "'>" + data[i].communityName + "</option>");
			            }
			            if('${rLevel}'==3 || '${rLevel}'==4){
				            $("#communityId").select2({
				                "placeholder": "请选择",
				                "width": "100%"
				            })
				        }else{
				            $("#communityId").select2({
				                "placeholder": "请选择小区",
				                "width": "100%"
				            })
					    }
			        }, "json");
                }
                <!--查询-->
                jQuery("#query").click(query);
                jQuery("#resetForm").click(resetForm);
            });

    <!--刷新jqGrid表格数据-->
    function refreshGrid() {
        $("#jqGrid").trigger("reloadGrid");
    }
    function resetForm() {
        location.reload();
        return false;
    }
   //修改钥匙有效期
    function overdueKeys(sid,validity){
    	layer.open({
            type: 2,
            title: ['修改钥匙有效期', 'font-weight:bold'],
            shadeClose: true, //点击遮罩关闭层
            area: ['387px', '358px'],
            scrollbar: false,
            content: '${pageContext.request.contextPath}/admin/tkeys_changeKeysValidity.action?sid='+sid+'&validity='+validity,
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var options = {
                    success: function (data) {
                        data = JSON.parse(data);
                        if (data.code == 1) {
                            layer.alert(data.msg, function () {
                                layer.closeAll();
                                refreshGrid();
                            });
                        } else {
                            layer.alert(data.msg);
                        }
                    }
                };
                $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
                $("#layui-layer-iframe" + index).contents().find("#form").submit();
            },
            cancel: function (index, layero) {
                layer.close(index);
            }
        });
    }
   
    
    //修改钥匙有效期
    function changeKeys(sid,status){
    	 $.post("${pageContext.request.contextPath}/admin/tkeys_changeKeys.action", {
  	    	'sid':sid,
  	    	'status':status
           }, function (result) {
               result = JSON.parse(result)
               if(result.code == 1){
            	   refreshGrid();
               }
               layer.alert(result.msg);
               
           });
    }
    
    function query() {
        var $agtCode = $("#agtCode").val();
        var $communityId = $("#communityId").val();
        var $cityCode = $("#cityCode").val();
        var $reqtime = $("#reqtime").val();
        var $validity = $("#validity").val();
        var $userName = $("#userName").val();
        var $pid = $("#pid").val();
        var $cbName = $("#cbName").val();
        var $tel = $("#tel").val();
        $("#jqGrid").jqGrid('setGridParam', {
            url: "${pageContext.request.contextPath}/admin/tkeys_page.action",
            postData: {
                'agtCode': $agtCode,
                'communityId': $communityId,
                'cityCode': $cityCode,
                'reqtime': $reqtime,
                'validity': $validity,
                'userName': $userName,
                'pid': $pid,
                'cbName': $cbName,
                'tel': $tel
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入*/
        return false;
    };
    $("#communityId").select2({
        "placeholder": "请选择社区",
        "minimumResultsForSearch":-1
    })
	window.onload=function(){
		function BrowserType(){
			//获取浏览器的userAgent代理号；
			var userAgent=navigator.userAgent;
			
			//判断是否是Opera浏览器
			var isOpera=userAgent.indexOf("Opera")>-1;
			//判断是否是IE浏览器
			var isIE=userAgent.indexOf("compatible")>-1 && userAgent.indexOf("MSIE")>-1 && !isOpera;
			//判断是否是IE7浏览器
			if(isIE){
				var relIE=new RegExp("MSIE(\\d+\\.\\d+);");
				
				relIE.test(userAgent);
				var arr=userAgent.split(";")
				var flEVersion=arr[1].indexOf("7");
				if(flEVersion>-1){
					var $td=$(".jqgrid-rownum")[0];
				$td.style.width="0";
					$tr=$("thead tr th");
					var t=$("tbody tr")[2];
					
					var d=t.getElementsByTagName("td");
					d[0].style.width=10+"px";
					$td=$("tbody tr td");
					var len=$tr.length;
					for(var i=0;i<len;i++){
						$tr[i].style.width=30+"px";
						
						$td[i].style.width=30+"px";
						
					};
				}
			}
		};
		BrowserType();
	};
</script>
</body>
</html>
